
package com.horizon.mobile.view;

import zuo.biao.library.base.BaseModel;
import zuo.biao.library.base.BaseView;
import zuo.biao.library.ui.WebViewActivity;
import zuo.biao.library.util.Log;
import zuo.biao.library.util.StringUtil;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.horizon.mobile.R;
import com.horizon.mobile.activity.FlowDetailActivity;
import com.horizon.mobile.model.Todo;
import com.horizon.mobile.model.User;

/**
 * 用户View
 * 
 * @author 左大明
 * @use <br>
 *      UserView userView = new UserView(context, resources); <br>
 *      adapter中使用:[具体参考.BaseViewAdapter(getView使用自定义View的写法)] <br>
 *      convertView = userView.createView(inflater); <br>
 *      userView.bindView(position, data); <br>
 *      或 其它类中使用: <br>
 *      containerView.addView(userView.createView(inflater)); <br>
 *      userView.bindView(data); <br>
 *      然后 <br>
 *      userView.setOnDataChangedListener(onDataChangedListener);data =
 *      userView.getData();//非必需 <br>
 *      userView.setOnClickListener(onClickListener);//非必需
 */
public class UserView extends BaseView<Todo> implements OnClickListener {
	private static final String TAG = "UserView";

	public UserView(Activity context, Resources resources) {
		super(context, resources);
	}

	public TextView tvFlowName;

	public TextView tvTitle;
	public TextView tvTime;

	@SuppressLint("InflateParams")
	@Override
	public View createView(LayoutInflater inflater) {
		convertView = inflater.inflate(R.layout.todo_view, null);
		tvFlowName = findViewById(R.id.tvFlowname, this);
		tvTitle = findViewById(R.id.tvTitle, this);
		tvTime = findViewById(R.id.tvTime, this);
		return convertView;
	}

	@Override
	public void bindView(Todo data){
		if (data == null) {
			Log.e(TAG, "bindView data == null >> data = new User(); ");
			data = new Todo();
		}
		this.data = data;
		tvFlowName.setText(StringUtil.getTrimedString(data.getFlowName()));
		tvTitle.setText( StringUtil.getNoBlankString(data.getTitle()));
		tvTime.setText(StringUtil.getNoBlankString(data.getSendTime()));
	}

	@Override
	public void onClick(View v) {
		if (BaseModel.isCorrect(data) == false) {
			return;
		}
		toActivity(FlowDetailActivity.createIntent(context,
				data.getWorkId(), data
						.getTitle(),data.getTrackId(),data.getSubjectionId()));
//		switch (v.getId()) {
//		
//		}
	}
}